<html>
  <head>
    <title>DOM tests for narcissus</title>
    <script type="text/javascript">
        alert("spidermonkey");
    </script>
    <script type="application/narcissus">
        alert("narcissus");
    </script>
	
	<script type="text/narcissus" src="http://bikingladies.be/kul/jstest/test.js"></script>
       
	<!--<script type="text/narcissus" >
		//alert("help");
		//alert(typeof(test));
		//test();
		//alert(typeof window.XMLHttpRequest);
		//var x = new XMLHttpRequest();
		//alert("wut");
	</script>-->
	
	<script type="text/narcissus">
            /*t("on"+k,o)}if(z.add){z.add.call(a,j);if(!j.handler.guid)j.handler.guid=d.guid}u.push(j);c.event.global[k]=true}a=null}}},global:{},remove:function(a,b,d,f){if(!(a.nodeType===3||a.nodeType===8)){var e,j=0,i,o,k,n,r,u,z=c.data(a),
C=z&&z.
function testJQ()
{
	var s = new SamObj();
	alert(s.testdoc() + " -- alert1");
	// jQuery +- line 5000 fails
	// jQuery xhr fails, known issue
	alert(jQuery("body").html() + " -- alert2");
	alert("t2: "+s.testdoc() + " -- alert3");
	return false;
	var list = jQuery("#successlist").toArray();
	for(var i in list)
	{
		alert(list[i]  + " -- alert" + (i + 3));
	}
	return false;
}
testJQ();*/
              function getText( elems ){
		var ret = "", elem;
		// werkt wel
			// for ( var i = 0; i < elems.length; i++ )
			// for ( var i in elems )
		// werkt niet
			// for ( var i = 0; elems[i]; i++ )
		alert(elems.length);
		for ( var i = 0; elems[i]; i++ ) {
			elem = elems[i];
			elem.nodeType;
			ret+=i+", ";
			// Get the text from text nodes and CDATA nodes
			if ( elem.nodeType === 3 || elem.nodeType === 4 ) {
				ret += elem.nodeValue;

			// Traverse everything else, except comment nodes
			} else if ( elem.nodeType !== 8 ) {
				ret += getText( elem.childNodes );
			}
		}
		return ret;
            }
                 alert(getText(document.body.childNodes));
		test();
		alert(typeof window.XMLHttpRequest);
		var x = new XMLHttpRequest();
		alert(x);
	</script>
    <script type="text/narcissus">
        function AssertError(message) {
            this.name = "AssertError";
            this.message = message || "Assertion failed";
        }
        AssertError.prototype = new Error();
        AssertError.prototype.constructor = AssertError;

        /*
        * assertEq(actual, expected [, message])
        *   Throw if the two arguments are not the same.  The sameness of two values
        *   is determined as follows.  If both values are zero, they are the same iff
        *   their signs are the same.  Otherwise, if both values are NaN, they are the
        *   same.  Otherwise, they are the same if they compare equal using ===.
        * see https://bugzilla.mozilla.org/show_bug.cgi?id=480199 and
        *     https://bugzilla.mozilla.org/show_bug.cgi?id=515285
        */
        var assertEquals =
            function (actual, expected, message)
            {
                function SameValue(v1, v2)
                {
                    if (v1 === 0 && v2 === 0)
                        return 1 / v1 === 1 / v2;
                    if (v1 !== v1 && v2 !== v2)
                        return true;
                    return v1 === v2;
                }
                if (!SameValue(actual, expected))
                {
                    throw new AssertError('Assertion failed: got "' + actual + '", expected "' + expected +
                            (message ? ": " + message : ""));
                }
            };

        function assertTrue(actual) {
            assertEquals(actual, true);
        }

        function assertFalse(actual) {
            assertEquals(actual, false);
        }

    </script>
  </head>
  <body>
      <div id="container">
        <p id="tag1">value1</p>
        <p id="tag2">value2</p>
      </div>
      <script type="text/narcissus">
          var one = document.getElementById("tag1");
          var two = document.getElementById("tag2");

          try {
            assertEquals(one.innerHTML, "value1");
            assertEquals(two.innerHTML, "value2");
           } catch(e) {
                alert(e.name + ": " + e.message);
           }

           var newel = document.createElement('p');

           newel.setAttribute('id','added1');
           newel.innerHTML = "Succes!";
           //newel.style.backgroundColor = "#00FF00";
            
           document.getElementById("container").appendChild(newel);

           try {
                assertEquals(document.getElementById("added1").innerHTML, "Succes!");
           } catch(e) {
                alert(e.name + ": " + e.message);
           }

      </script>
  </body>
</html>
